lets_plot package¶
Subpackages¶
- lets_plot.export package
- lets_plot.frontend_context package
- lets_plot.geo_data package
- lets_plot.plot package
- lets_plot.plot.coord module
- lets_plot.plot.core module
- lets_plot.plot.facet module
- lets_plot.plot.geom module
- lets_plot.plot.geom_extras module
- lets_plot.plot.geom_image_ module
- lets_plot.plot.geom_livemap_ module
- lets_plot.plot.guide module
- lets_plot.plot.image_matrix module
- lets_plot.plot.label module
- lets_plot.plot.plot module
- lets_plot.plot.pos module
- lets_plot.plot.sampling module
- lets_plot.plot.scale module
- lets_plot.plot.scale_convenience module
- lets_plot.plot.scale_identity module
- lets_plot.plot.theme_ module
- lets_plot.plot.tooltip module
Submodules¶
lets_plot.mapping module¶
-
class
lets_plot.mapping.MappingMeta(variable, annotation, **parameters)¶ Bases:
object
-
lets_plot.mapping.as_discrete(variable, label=None)¶ Marks a numeric variable as categorical.
- Parameters
variable (string) – The name of the variable
label (string) – The name of the scale - used as the axis label or the legend title
- Returns
- Return type
variable meta information
Notes
The plot will use a discrete scale for the aesthetic mapping. It is similar to the factor() function from R but works differently - there is no data transformation.
Examples
>>> df = { >>> 'x': [0, 5, 10, 15], >>> 'y': [0, 5, 10, 15], >>> 'a': [1, 2, 3, 2] >>> } >>> ggplot(df, aes(x='x', y='y')) + geom_point(aes(color=pm.as_discrete('a')), size=9)
lets_plot.settings_utils module¶
-
lets_plot.settings_utils.maptiles_zxy(url: str) → dict¶ - Parameters
url – Template for a standard raster ZXY tile provider with {z}, {x} and {y} wildcards, e.g. ‘http://my.tile.com/{z}/{x}/{y}.png’
- Returns
Tile provider settings
Module contents¶
-
lets_plot.coord_cartesian(xlim=None, ylim=None)¶
-
lets_plot.coord_fixed(ratio=1.0, xlim=None, ylim=None)¶
-
lets_plot.coord_map(xlim=None, ylim=None)¶
-
lets_plot.aes(x=None, y=None, **other)¶ Define aesthetic mappings
- Parameters
x, y, … (List of name value pairs giving aesthetics to map to variables.)
The names for x and y aesthetics are typically omitted because they are so common; all other aesthetics must be named.
- Returns
- Return type
aesthetic mapping specification
Note
Generates aesthetic mappings that describe how variables in the data are projected to visual properties (aesthetics) of geometries. This function also standardizes aesthetic names by, for example, converting colour to color.
Aesthetic mappings are not to be confused with aesthetic settings; the latter are used to set aesthetics to some constant values, e.g. make all points red in the plot. If one wants to make the color of a point depend on the value of a variable, he/she should project this variable to the color aesthetic via aesthetic mapping.
Examples
>>> import numpy as np >>> import pandas as pd >>> x = np.random.uniform(-1, 1, size=100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(100)] >>> ggplot(dat) + geom_point(aes(x='x', y='y', color='y', shape='class', fill='x', size='y')) + ... geom_point(shape=21, color='red', fill='green', size=5, stat='smooth')
-
lets_plot.layer(geom=None, stat=None, data=None, mapping=None, position=None, **kwargs)¶ Create a new layer
- Parameters
geom (string) – The geometric object to use to display the data
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
mapping (dictionary, optional) – Set of aesthetic mappings created by aes. Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
kwargs – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
A layer is a combination of data, stat and geom with a potential position adjustment. Usually layers are created using geom_* or stat_* calls but they can be created directly using this function.
Examples
>>> import numpy as np >>> import pandas as pd >>> x = np.random.uniform(-1, 1, size=100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(100)] >>> ggplot(dat, aes(x='x', y='y', group='class', color='class')) + layer(geom='point', stat='smooth', position='identity')
todo: other parameters: inherit.aes = TRUE, subset = NULL, show.legend = NA
-
lets_plot.facet_grid(x=None, y=None)¶ Lay out panels in a grid.
- Parameters
x (string, optional) – Feature, which defines columns of the facet grid to be displayed.
y (string, optional) – Feature, which defines rows of the facet grid to be displayed.
- Returns
- Return type
facet grid specification
Note
Lay out panels in a grid.
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> from scipy.stats import norm >>> from lets_plot import * >>> LetsPlot.setup_html() >>> mean=norm(loc=0, scale=5).rvs(size=3) >>> X = multivariate_normal(mean=mean, cov=0.1).rvs(1000) >>> df=pd.melt(pd.DataFrame(X)) >>> ggplot(df)+geom_histogram()+facet_grid(y='variable')
-
lets_plot.geom_point(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, map=None, map_join=None, animation=None, tooltips=None, **other_args)¶ Points, as for a scatter plot.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary, pandas DataFrame or GeoDataFrame (supported shapes Point and MultiPoint), optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer.
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
animation (type of the animation, optional) – Codes and names: 0 = “none” (default), 1 = “ripple”.
map (GeoDataFrame (supported shapes Point and MultiPoint) or Regions (implicitly invoke centroids())) – Data containing coordinates of points.
map_join (str, pair, optional) – Pair of names used to join map coordinates with data. str is allowed only when used with Regions object - map key ‘request’ will be automatically added. first value in pair - column in data second value in pair - column in map
other_args – Other arguments passed on to the layer. These are often aesthetics settings used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
The point geometry is used to create scatterplots. The scatterplot is useful for displaying the relationship between two continuous variables, although it can also be used with one continuous and one categorical variable, or two categorical variables. geom_point understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
- alphatransparency level of the point
Understands numbers between 0 and 1.
- color (colour)color of the geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- fillcolor to paint shape’s inner points
Is applied only to the points of shapes having inner points.
shape : shape of the point
size : size of the point
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> x = np.random.uniform(-1, 1, size=100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(100)] >>> p = ggplot(dat) + geom_point(aes(x='x', y='y', color='y', shape='class', fill='x', size='y')) >>> p += geom_point(aes(x='x', y='y'), shape=21, color='gray', fill='light_blue', size=5, alpha=0.5, stat='smooth') >>> p += theme(legend_direction='horizontal') + ggsize(650, 350) >>> p
-
lets_plot.geom_path(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, map=None, map_join=None, animation=None, tooltips=None, **other_args)¶ Connects observations in the order, how they appear in the data.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary, pandas DataFrame or GeoDataFrame (supported shapes LineString and MultiLineString), optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
animation (type of the animation, optional) – Codes and names: 0 = “none” (default), 1 = “dash”, 2 = “plane”, 3 = “circle”.
map (GeoDataFrame (supported shapes LineString and MultiLineString)) – Data containing coordinates of lines.
map_join (str, pair, optional) – Pair of names used to join map coordinates with data. str is allowed only when used with Regions object - map key ‘request’ will be automatically added. first value in pair - column in data second value in pair - column in map
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_path connects the observations in the order in which they appear in the data. geom_path lets you explore how two variables are related over time. geom_path understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
- alphatransparency level of a point
Understands numbers between 0 and 1.
- color (colour)color of a geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- linetypetype of the line
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
size : line width
- speedanimation speed
The number of pixels covered by animation object per second. Default value is 10.
- flowanimation flow
The number of animation objects passing a reference point per second. Default value is 0.1.
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> T = 1 >>> N = 1000 >>> t = np.linspace(0, T, N) >>> dt = T / N >>> # brownian motions >>> W1 = np.random.standard_normal(size=N) >>> Wt1 = np.cumsum(W1) * np.sqrt(dt) >>> W2 = np.random.standard_normal(size=N) >>> Wt2 = np.cumsum(W2) * np.sqrt(dt) >>> dat = {} >>> dat['W1'] = Wt1 >>> dat['W2'] = Wt2 >>> dat['t'] = t >>> # plot brownian motion path >>> ggplot(dat) + geom_path(aes(x='W1', y='W2')) >>> # transform data via melt function >>> # to produce two trajectories >>> dat = pd.DataFrame(dat) >>> dat = pd.melt(dat, id_vars=['t'], value_vars=['W1', 'W2']) >>> p = ggplot(dat, aes(x='t', y='value', group='variable')) >>> p += geom_path(aes(color='variable', linetype='variable'), size=1, alpha=0.5) >>> p += geom_path(stat='smooth', color='red', linetype='longdash') >>> p
-
lets_plot.geom_line(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Connect points in order of the variable on the x-axis
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_line connects the observations in the order of the variable on the x axis. geom_line can be used to plot time series. geom_line understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
- alphatransparency level of a point
Understands numbers between 0 and 1.
- color (colour)color of a geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- linetypetype of the line
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
size : line width
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> T = 1 >>> N = 1000 >>> t = np.linspace(0, T, N) >>> dt = T / N >>> # brownian motions >>> W1 = np.random.standard_normal(size=N) >>> Wt1 = np.cumsum(W1) * np.sqrt(dt) >>> W2 = np.random.standard_normal(size=N) >>> Wt2 = np.cumsum(W2) * np.sqrt(dt) >>> dat = {} >>> dat['W1'] = Wt1 >>> dat['W2'] = Wt2 >>> dat['t'] = t >>> # transform data via melt function >>> # to produce two trajectories >>> dat = pd.DataFrame(dat) >>> dat = pd.melt(dat, id_vars=['t'], value_vars=['W1', 'W2']) >>> p = ggplot(dat, aes(x='t', y='value', group='variable')) >>> p += geom_line(aes(color='variable', linetype='variable'), size=1, alpha=0.5) >>> p += geom_line(stat='smooth', color='red', linetype="longdash") >>> p
-
lets_plot.geom_smooth(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Add a smoothed conditional mean.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
method (smoothing method: lm (Linear Model) or loess (Locally Estimated Scatterplot Smoothing). Default - ‘lm’)
n (number of points to evaluate smoother at.)
se (boolean, to display confidence interval around smooth. Default - True)
level (level of confidence interval to use. Default - 0.95)
span (number, optional) – Only for LOESS method. The fraction of source points closest to the current point is taken into account for computing a least-squares regression. A sensible value is usually 0.25 to 0.5. Default - 0.5
deg (degree of polynomial for linear regression model. Default - 1)
seed (random seed for LOESS sampling.)
max_n (maximum number of data-points for LOESS method. If this quantity exceeded random sampling) – is applied to data. Default - 1000
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_smooth aids the eye in seeing patterns in the presence of overplotting. Computed variables:
y : predicted (smoothed) value
ymin : lower pointwise confidence interval around the mean
ymax : upper pointwise confidence interval around the mean
se : standard error
- geom_smooth understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
alpha : transparency level of a layer Understands numbers between 0 and 1.
color (colour) : color of a geometry Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
linetype : type of the line of conditional mean line Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
size : lines width Defines line width for conditional mean and confidence bounds lines.
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> from lets_plot import * >>> N = 100 >>> t = np.linspace(1, N, N) >>> a = 1 >>> b = 0 >>> M = 2 >>> A = np.random.standard_normal(M) / N + a >>> B = np.random.standard_normal(M) / N + b >>> mean = np.zeros(M) >>> cov = np.eye(M) >>> Z = multivariate_normal.rvs(mean, cov, N) >>> X = np.outer(B, t / N) >>> X = X + Z.T >>> X = X + (np.full((N, M), 1) * A).T >>> dat = pd.DataFrame(X.T) >>> dat = pd.melt(dat) >>> dat["t"] = np.tile(t / N, M) >>> ggplot(dat, aes(x='t', y='value', group='variable')) + geom_point(aes(color='variable')) + geom_smooth(color='red')
-
lets_plot.geom_bar(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Bar chart which makes the height of the bar proportional to the number of observed variable values, mapped to x axis.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_bar makes the height of the bar proportional to the number of observed variable values, mapped to x axis. Is intended to use for discrete data. If used for continuous data with stat=’bin’ produces histogram for binned data. geom_bar handles no group aesthetics. geom_bar understands the following aesthetics mappings:
x : x-axis value (this values will produce cases or bins for bars)
y : y-axis value (this value will be used to multiply the case’s or bin’s counts)
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
fill : color of geometry filling
- sizelines width
Defines bar line width
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> from lets_plot import * >>> N = 100 >>> M = 3 >>> mean = np.zeros(M) >>> mean = np.arange(M) * 5 >>> cov = np.eye(M) >>> X = multivariate_normal.rvs(mean, cov, N) >>> X = X.astype(int) # comment this line to make variables continuous back >>> dat = pd.DataFrame(X) >>> dat = pd.melt(dat) >>> ggplot(dat, aes(x='value')) + geom_bar(stat='bin', color='gray', fill='dark_green', size=2)
-
lets_plot.geom_histogram(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, bins=None, binwidth=None, center=None, boundary=None, tooltips=None, **other_args)¶ Displays a 1d distribution by dividing variable mapped to x axis into bins and counting the number of observations in each bin.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional, default: “bin”) – The statistical transformation to use on the data for this layer.
position (string, optional, default: “stack”) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
bins – Number of bins. Overridden by binwidth. Defaults to 30
binwidth – The width of the bins. The default is to use bin widths that cover the range of the data. You should always override this value, exploring multiple widths to find the best to illustrate the stories in your data.
center (number, optional) – Specifies x-value to align bin centers to.
boundary (number, optional) – Specifies x-value to align bin boundary (i.e. point berween bins) to.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_histogram displays a 1d distribution by dividing variable mapped to x axis into bins and counting the number of observations in each bin. geom_histogram understands the following aesthetics mappings:
x : x-axis value (this values will produce cases or bins for bars)
- yy-axis value, default: “..count..”.
Alternatively: ‘..density..’
weight : used by “bin” stat to compute weighted sum instead of simple count.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- colorcolor of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
fill : color of geometry filling
size : lines width
Examples
>>> import numpy as np >>> from lets_plot import * >>> >>> np.random.seed(123) >>> data = dict( >>> x = np.random.normal(0, 1, 100) >>> ) >>> ggplot(data) + geom_histogram(aes(x='x'), color='black', fill='gray', size=1)
-
lets_plot.geom_bin2d(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, bins=None, binwidth=None, drop=None, tooltips=None, **other_args)¶ Displays a 1d distribution by dividing variable mapped to x axis into bins and counting the number of observations in each bin.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, default: “bin”) – The statistical transformation to use on the data for this layer.
position (string, default: “stack”) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
bins (list of 2 numbers, default: [30,30]) – Number of bins in both directions, vertical and horizontal. Overridden by binwidth.
binwidth (list of 2 numbers, optional) – The width of the bins in both directions, vertical and horizontal. Overrides bins. The default is to use bin widths that cover the entire range of the data.
drop (bool, optional, default: True) – Specifies whether to remove all bins with 0 counts.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_bin2d applies rectangular grid to the plane then counts observation in each cell of the grid (bin). Uses geom_tile to display counts as a tile fill-color. geom_histogram understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
weight : used by “bin” stat to compute weighted sum instead of simple count.
- alphanumber in [0..1]
Transparency level of a layer
- colorcolor of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- fillcolor of geometry filling, default: “..count..”.
Alternatively: ‘..density..’
size : lines width
Examples
>>> import numpy as np >>> from lets_plot import * >>> >>> cov=[[1, 0], >>> [0, 1]] >>> x, y = np.random.multivariate_normal(mean=[0,0], cov=cov, size=400).T >>> >>> data = dict( >>> x = x, >>> y = y >>> ) >>> ggplot(data) + geom_bin2d(aes(x='x', y='y'), binwidth=[0.5,0.5])
-
lets_plot.geom_tile(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Rectangles with x, y values mapped to center
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
- Understands the following aesthetics mappings:
x : x-axis coordinates of the center of rectangles.
y : y-axis coordinates of the center of rectangles.
width : width of a tile.
height : height of a tile.
alpha : transparency level of a layer
color (colour) : color of a geometry lines
fill : color of geometry filling
size : lines width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> import numpy as np >>> import matplotlib.mlab as mlab >>> from lets_plot import * >>> delta = 0.5 >>> center_x = 6 >>> center_y = 6 >>> x = np.arange(-5.0, 5.0, delta) >>> y = np.arange(-5.0, 5.0, delta) >>> X, Y = np.meshgrid(x, y) >>> mu = np.array([1, 0]) >>> sigma = np.diag([1, 4]) >>> mu1 = np.array([0, 0]) >>> sigma1 = np.diag([4, 1]) >>> Z = multivariate_normal.pdf(np.dstack((X, Y)), mean=mu, cov=sigma) >>> Z = Z - multivariate_normal.pdf(np.dstack((X, Y)), mean=mu1, cov=sigma1) >>> x = X.reshape(-1) + center_x >>> y = Y.reshape(-1) + center_y >>> z = Z.reshape(-1) >>> dat = dict(x=x, y=y, z=z) >>> plot = ggplot(dat, aes('x', 'y')) + geom_tile(aes(fill='z'), width=.7, height=.7) >>> plot
-
lets_plot.geom_raster(mapping=None, data=None, stat=None, position=None, show_legend=None, tooltips=None, **other_args)¶ Rectangles with x, y values mapped to center. Much faster than geom_tile but doesn’t support width/height and color.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
- Understands the following aesthetics mappings:
x : x-axis coordinates of the center of rectangles.
y : y-axis coordinates of the center of rectangles.
alpha : transparency level of a layer
fill : color of geometry filling
Examples
>>> import numpy as np >>> import matplotlib.mlab as mlab >>> from lets_plot import * >>> delta = 0.5 >>> center_x = 6 >>> center_y = 6 >>> x = np.arange(-5.0, 5.0, delta) >>> y = np.arange(-5.0, 5.0, delta) >>> X, Y = np.meshgrid(x, y) >>> mu = np.array([1, 0]) >>> sigma = np.diag([1, 4]) >>> mu1 = np.array([0, 0]) >>> sigma1 = np.diag([4, 1]) >>> Z = multivariate_normal.pdf(np.dstack((X, Y)), mean=mu, cov=sigma) >>> Z = Z - multivariate_normal.pdf(np.dstack((X, Y)), mean=mu1, cov=sigma1) >>> x = X.reshape(-1) + center_x >>> y = Y.reshape(-1) + center_y >>> z = Z.reshape(-1) >>> dat = dict(x=x, y=y, z=z) >>> plot = ggplot(dat, aes('x', 'y')) + geom_raster(aes(fill='z')) >>> plot
-
lets_plot.geom_errorbar(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Error bars
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_errorbar represents a vertical interval, defined by x, ymin, ymax. geom_errorbar understands the following aesthetics mappings:
x : x-axis coordinates
ymin : lower bound for error bar.
ymax : upper bound for error bar.
width : width of a bar.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines bar line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> import numpy as np >>> from lets_plot import * >>> N = 10 >>> M = 10 >>> m = np.random.random(M) * 5.0 >>> cov = np.eye(M) >>> W = np.random.multivariate_normal(m, cov, N) >>> se = W.std(axis=1) >>> mean = W.mean(axis=1) >>> ymin = mean - se >>> ymax = mean + se >>> x = np.arange(0, N, 1) >>> dat = dict(x=x, ymin=ymin, ymax=ymax) >>> ggplot(dat, aes(x='x')) + geom_errorbar(aes(ymin='ymin', ymax='ymax'))
-
lets_plot.geom_crossbar(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, fatten=None, tooltips=None, **other_args)¶ Bar with horizontal median line
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer.
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
fatten (number, default: 2.5) – A multiplicative factor applied to size of the middle bar
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_crossbar represents a vertical interval, defined by x, ymin, ymax. The mean is represented by horizontal line. geom_crossbar understands the following aesthetics mappings:
x : x-axis coordinates
ymin : lower bound for error bar.
ymax : upper bound for error bar.
middle : position of median bar.
width : width of a bar.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
fill : color of geometry filling.
size : lines width.
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> from lets_plot import * >>> >>> data = dict( >>> supp = ['OJ', 'OJ', 'OJ', 'VC', 'VC', 'VC'], >>> dose = [0.5, 1.0, 2.0, 0.5, 1.0, 2.0], >>> length = [13.23, 22.70, 26.06, 7.98, 16.77, 26.14], >>> len_min = [11.83, 21.2, 24.50, 4.24, 15.26, 23.35], >>> len_max = [15.63, 24.9, 27.11, 10.72, 19.28, 28.93] >>> ) >>> >>> p = ggplot(data, aes(x='dose', color='supp')) >>> p += geom_crossbar(aes(ymin='len_min', ymax='len_max', middle='length'), fatten=5) >>> p
-
lets_plot.geom_linerange(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Line range, defined by an upper and lower value
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer.
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_linerange represents a vertical interval, defined by x, ymin, ymax. geom_linerange understands the following aesthetics mappings:
x : x-axis coordinates
ymin : lower bound for line range.
ymax : upper bound for line range.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
size : lines width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> from lets_plot import * >>> >>> data = dict( >>> supp = ['OJ', 'OJ', 'OJ', 'VC', 'VC', 'VC'], >>> dose = [0.5, 1.0, 2.0, 0.5, 1.0, 2.0], >>> length = [13.23, 22.70, 26.06, 7.98, 16.77, 26.14], >>> len_min = [11.83, 21.2, 24.50, 4.24, 15.26, 23.35], >>> len_max = [15.63, 24.9, 27.11, 10.72, 19.28, 28.93] >>> ) >>> >>> p = ggplot(data, aes(x='dose', color='supp')) >>> p += geom_linerange(aes(ymin='len_min', ymax='len_max')) >>> p
-
lets_plot.geom_pointrange(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, fatten=None, tooltips=None, **other_args)¶ Vertical line defined by upper and lower value with mid-point at Y-location.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer.
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
fatten (number, default: 5.0) – A multiplicative factor applied to size of the middle bar
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_pointrange represents a vertical interval, defined by x, ymin, ymax. The mid-point is defined by y. geom_pointrange understands the following aesthetics mappings:
x : x-axis coordinates
y : position of mid-point.
ymin : lower bound for error bar.
ymax : upper bound for error bar.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines.
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
fill : color of geometry filling.
size : lines width, size of mid-point.
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
shape : shape of the mid-point
Examples
>>> from lets_plot import * >>> >>> data = dict( >>> supp = ['OJ', 'OJ', 'OJ', 'VC', 'VC', 'VC'], >>> dose = [0.5, 1.0, 2.0, 0.5, 1.0, 2.0], >>> length = [13.23, 22.70, 26.06, 7.98, 16.77, 26.14], >>> len_min = [11.83, 21.2, 24.50, 4.24, 15.26, 23.35], >>> len_max = [15.63, 24.9, 27.11, 10.72, 19.28, 28.93] >>> ) >>> >>> p = ggplot(data, aes(x='dose', color='supp')) >>> p += geom_pointrange(aes(ymin='len_min', ymax='len_max', y='length'), fatten=5) >>> p
-
lets_plot.geom_contour(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, bins=None, binwidth=None, tooltips=None, **other_args)¶ Display contours of a 3d surface in 2d.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
bins (int, optional) – Number of levels.
binwidth (double, optional) – Distance between levels.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
- geom_contour() displays contours of a 3d surface in 2d.
- Computed variables:
level : height of a contour
- geom_contour understands the following aesthetics mappings:
x : x-axis coordinates of the center of rectangles, forming a tessellation.
y : y-axis coordinates of the center of rectangles, forming a tessellation.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines bar line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> import numpy as np >>> import pandas as pd >>> import matplotlib.mlab as mlab >>> from lets_plot import * >>> delta = 0.5 >>> center_x = 6 >>> center_y = 6 >>> x = np.arange(-5.0, 5.0, delta) >>> y = np.arange(-5.0, 5.0, delta) >>> X, Y = np.meshgrid(x, y) >>> mu = np.array([1, 0]) >>> sigma = np.diag([1, 4]) >>> mu1 = np.array([0, 0]) >>> sigma1 = np.diag([4, 1]) >>> Z = multivariate_normal.pdf(np.dstack((X, Y)), mean=mu, cov=sigma) >>> Z = Z - multivariate_normal.pdf(np.dstack((X, Y)), mean=mu1, cov=sigma1) >>> x = X.reshape(-1) + center_x >>> y = Y.reshape(-1) + center_y >>> z = Z.reshape(-1) >>> dat = dict(x=x, y=y, z=z) >>> p = ggplot(dat, aes('x', 'y')) + geom_tile(aes(fill='z')) + geom_contour(aes(z='z', color='..level..')) + scale_color_gradient(low='dark_green', high='yellow') >>> p
-
lets_plot.geom_contourf(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, bins=None, binwidth=None, tooltips=None, **other_args)¶ Fill contours of a 3d surface in 2d.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
bins (int, optional) – Number of levels.
binwidth (double, optional) – Distance between levels.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_contourf() fills contours of a 3d surface in 2d. Computed variables:
level : height of a contour
- geom_contour understands the following aesthetics mappings:
x : x-axis coordinates of the center of rectangles, forming a tessellation.
y : y-axis coordinates of the center of rectangles, forming a tessellation.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- fillcolor of a geometry areas
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
Examples
>>> import numpy as np >>> import pandas as pd >>> import matplotlib.mlab as mlab >>> from lets_plot import * >>> delta = 0.5 >>> center_x = 6 >>> center_y = 6 >>> x = np.arange(-5.0, 5.0, delta) >>> y = np.arange(-5.0, 5.0, delta) >>> X, Y = np.meshgrid(x, y) >>> mu = np.array([1, 0]) >>> sigma = np.diag([1, 4]) >>> mu1 = np.array([0, 0]) >>> sigma1 = np.diag([4, 1]) >>> Z = multivariate_normal.pdf(np.dstack((X, Y)), mean=mu, cov=sigma) >>> Z = Z - multivariate_normal.pdf(np.dstack((X, Y)), mean=mu1, cov=sigma1) >>> x = X.reshape(-1) + center_x >>> y = Y.reshape(-1) + center_y >>> z = Z.reshape(-1) >>> dat = dict(x=x, y=y, z=z) >>> p = ggplot(dat, aes('x', 'y', z='z')) + geom_contourf(aes(fill='..level..')) >>> p
-
lets_plot.geom_polygon(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, map=None, map_join=None, tooltips=None, **other_args)¶ Display a polygon (filled path).
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary, pandas DataFrame or GeoDataFrame (supported shapes Polygon and MultiPolygon), optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
map (GeoDataFrame (supported shapes Polygon and MultiPolygon) or Regions (implicitly invoke boundaries())) – Data contains coordinates of polygon vertices on map.
map_join (str, pair, optional) – Pair of names used to join map coordinates with data. str is allowed only when used with Regions object - map key ‘request’ will be automatically added. first value in pair - column in data second value in pair - column in map
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_polygon draws polygons, which are filled paths. Each vertex of the polygon requires a separate row in the data. geom_polygon understands the following aesthetics mappings:
x : x-axis coordinates of the vertices of the polygon.
y : y-axis coordinates of the vertices of the polygon.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> import numpy as np >>> from lets_plot import * >>> id = ["A", "B", "C", "D", "E", "F"] >>> val = np.random.uniform(3, 3.5, 6) >>> x = np.random.uniform(1, 3, 18) >>> y = np.random.uniform(0, 3, 18) >>> id3 = [v for v in id for _ in range(3)] >>> val3 = [v for v in val for _ in range(3)] >>> dat = dict(id=id3, val=val3, x=x, y=y) >>> ggplot(dat, aes('x', 'y')) + geom_polygon(aes(fill='id'), alpha=0.5)
-
lets_plot.geom_map(mapping=None, data=None, stat=None, show_legend=None, sampling=None, map=None, map_join=None, tooltips=None, **other_args)¶ Display polygons from a reference map.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary, pandas DataFrame or GeoDataFrame (supported shapes Polygon and MultiPolygon), optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
map (GeoDataFrame (supported shapes Polygon and MultiPolygon) or Regions (implicitly invoke boundaries())) – Data containing region boundaries (coordinates of polygon vertices on map).
map_join (str, pair, optional) – Pair of names used to join map coordinates with data. str is allowed only when used with Regions object - map key ‘request’ will be automatically added. first value in pair - column in data second value in pair - column in map
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_map draws polygons which boundaries are specified by ‘map’ parameter. Aesthetics of ploygons (fill etc.) are computed basing on input data and mapping (see ‘data’ and ‘mapping’ arguments). geom_map understands the following aesthetics: - alpha : transparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- fillcolor of a geometry internals
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines bar line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> import lets_plot.geo_data as gd >>> boundaries = gd.regions_state(request=['Texas', 'Iowa', 'Arizona'], within='US-48').boundaries() >>> regions = np.unique(boundaries['found name']) >>> num_of_regions = len(regions) >>> df = pd.DataFrame(regions, columns=['state']) >>> df['value'] = np.random.rand(num_of_regions) >>> ggplot(df) + ggtitle('Randomly colored states') + geom_map(aes(fill='value'), map=boundaries, map_join=('state', 'found name'), color='white')
The geodata is provided by © OpenStreetMap contributors and is made available here under the Open Database License (ODbL).
-
lets_plot.geom_abline(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, slope=None, intercept=None, tooltips=None, **other_args)¶ Add straight lines to a plot specified by slope and intercept.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
slope – The line slope.
intercept – The value of y at the point where the line crosses the y axis.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
- geom_abline understands the following aesthetics mappings:
slope : line slope
intercept : line y-intercept
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines bar line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> from lets_plot import * >>> ggplot() + geom_abline(intercept=1, slope=3, color='red', linetype='dashed', size=3)
-
lets_plot.geom_hline(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, yintercept=None, tooltips=None, **other_args)¶ Add straight horizontal lines to a plot
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
yintercept – The value of y at the point where the line crosses the y axis.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
- geom_hline understands the following aesthetics mappings:
yintercept : line y-intercept
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines bar line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> from lets_plot import * >>> ggplot() + geom_hline(yintercept=0.2, color='dark_blue', linetype='longdash', size=2)
-
lets_plot.geom_vline(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, xintercept=None, tooltips=None, **other_args)¶ Add straight vertical lines to a plot
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
xintercept – The value of x at the point where the line crosses the x axis.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
- geom_hline understands the following aesthetics mappings:
xintercept : line x-intercept
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines bar line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> from lets_plot import * >>> ggplot() + geom_vline(xintercept=0.2, color='dark_green', linetype='dotdash', size=2)
-
lets_plot.geom_boxplot(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, fatten=None, outlier_color=None, outlier_fill=None, outlier_shape=None, outlier_size=None, varwidth=None, tooltips=None, **other_args)¶ - Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged) should be used to define boxplot from your own computations via lower, upper, ymin, ymax, middle aesthetics mappings (see below), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
fatten (number, default: 1.0) – A multiplicative factor applied to size of the middle bar
outlier_color, outlier_fill, outlier_shape, outlier_size – Default aesthetics for outliers.
varwidth – if FALSE (default) make a standard box plot. If TRUE, boxes are drawn with widths proportional to the square-roots of the number of observations in the groups.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
- geom_boxplot understands the following aesthetics mappings:
lower : lower hinge, 25% quantile
middle : median, 50% quantile
upper : upper hinge, 75% quantile
ymin : lower whisker = smallest observation greater than or equal to lower hinge - 1.5 * IQR
ymax : upper whisker = largest observation less than or equal to upper hinge + 1.5 * IQR
width : width of boxplot [0..1]
- alphatransparency level of a layer
Understands numbers between 0 and 1.
color (colour) : color of a geometry lines
fill : color of geometry filling
size : lines width
- linetypetype of the line of border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> from pandas import DataFrame >>> import numpy as np >>> from lets_plot import * >>> >>> np.random.seed(123) >>> data = DataFrame(dict( >>> cond=np.repeat(['A','B'], 200), >>> rating=np.concatenate((np.random.normal(0, 1, 200), np.random.normal(.8, 1, 200))) >>> )) >>> p = ggplot(data, aes(x='cond', y='rating')) + ggsize(300, 200) >>> p += geom_boxplot(outlier_color='red', outlier_shape=8, outlier_size=5) >>> p
-
lets_plot.geom_ribbon(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Display a ribbon.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_ribbon draws a ribbon bounded by ymin and ymax. geom_ribbon understands the following aesthetics mappings:
x : x-axis coordinates.
ymin : y-axis coordinates of the lower bound.
ymax : y-axis coordinates of the upper bound.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
fill : color of geometry filling
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> id = ["A", "A", "A", "B", "B", "B"] >>> x = [1, 2, 4, 1, 3, 4] >>> ymin = [-1, 0, 0, 3, 3, 4] >>> ymax = [0, 1, 1, 4, 5, 5] >>> dat = dict(id=id, x=x, ymin=ymin, ymax=ymax) >>> ggplot(dat) + geom_ribbon(aes(x='x', ymin='ymin', ymax='ymax', group='id', fill='id'), color='black', alpha=0.5)
-
lets_plot.geom_area(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Display an area.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_area draws an area bounded by the data and x axis. geom_area understands the following aesthetics mappings:
x : x-axis coordinates.
y : y-axis coordinates.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
fill : color of geometry filling
Examples
>>> from lets_plot import * >>> x = [1,3,4,1,3,4] >>> y = [1,1,2,3,4,2] >>> g = [1,1,1,2,2,2] >>> dat = dict(x=x, y=y, g=g) >>> ggplot(dat,aes('x','y', group='g')) + geom_area(aes(fill='g', color='g'), alpha=.2) + scale_fill_discrete() + scale_color_discrete()
-
lets_plot.geom_density(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, kernel=None, adjust=None, bw=None, n=None, tooltips=None, **other_args)¶ Display density function.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
kernel (string, optional) – The kernel we use to calculate the density function. Choose among “gaussian”, “cosine”, “optcosine”, “rectangular” (or “uniform”), “triangular”, “biweight” (or “quartic”), “epanechikov” (or “parabolic”)
bw (string or double, optional) – The method (or exact value) of bandwidth. Either a string (choose among “nrd0” and “nrd”), or a double.
adjust (double, optional) – Adjust the value of bandwidth my multiplying it. Changes how smooth the frequency curve is.
n (int, optional) – The number of sampled points for plotting the function
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_density draws density function. geom_density understands the following aesthetics mappings:
x : x-axis coordinates.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
fill : color of geometry filling
weight : used by “density” stat to compute weighted density.
Examples
>>> import numpy as np >>> from lets_plot import * >>> x = np.random.normal(0,1,1000) >>> dat = dict(x=x) >>> ggplot(dat,aes('x')) + geom_density()
-
lets_plot.geom_density2d(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, kernel=None, adjust=None, bw=None, n=None, bins=None, binwidth=None, tooltips=None, **other_args)¶ Display density function contour.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
kernel (string, optional) – The kernel we use to calculate the density function. Choose among “gaussian”, “cosine”, “optcosine”, “rectangular” (or “uniform”), “triangular”, “biweight” (or “quartic”), “epanechikov” (or “parabolic”)
bw (string or double array, optional) – The method (or exact value) of bandwidth. Either a string (choose among “nrd0” and “nrd”), or a double array of length 2.
adjust (double, optional) – Adjust the value of bandwidth my multiplying it. Changes how smooth the frequency curve is.
n (int array, optional) – The number of sampled points for plotting the function (on x and y direction correspondingly)
bins (int, optional) – Number of levels.
binwidth (double, optional) – Distance between levels.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_density2d draws density function. geom_density understands the following aesthetics mappings:
x : x-axis coordinates.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> import numpy as np >>> from lets_plot import * >>> x = np.random.normal(0,1,1000) >>> y = np.random.normal(0,1,1000) >>> dat = dict(x=x, y=y) >>> ggplot(dat,aes('x', 'y')) + geom_density2d()
-
lets_plot.geom_density2df(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, kernel=None, adjust=None, bw=None, n=None, bins=None, binwidth=None, tooltips=None, **other_args)¶ Fill density function contour.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
kernel (string, optional) – The kernel we use to calculate the density function. Choose among “gaussian”, “cosine”, “optcosine”, “rectangular” (or “uniform”), “triangular”, “biweight” (or “quartic”), “epanechikov” (or “parabolic”)
bw (string or double array, optional) – The method (or exact value) of bandwidth. Either a string (choose among “nrd0” and “nrd”), or a double array of length 2.
adjust (double, optional) – Adjust the value of bandwidth my multiplying it. Changes how smooth the frequency curve is.
n (int array, optional) – The number of sampled points for plotting the function (on x and y direction correspondingly)
bins (int, optional) – Number of levels.
binwidth (double, optional) – Distance between levels.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_density2df fills density contours. geom_density understands the following aesthetics mappings:
x : x-axis coordinates.
- alphatransparency level of a layer
Understands numbers between 0 and 1.
fill : color of geometry filling
Examples
>>> import numpy as np >>> from lets_plot import * >>> x = np.random.normal(0,1,1000) >>> y = np.random.normal(0,1,1000) >>> dat = dict(x=x, y=y) >>> ggplot(dat,aes('x', 'y')) + geom_density2df(aes(fill='..level..'))
-
lets_plot.geom_jitter(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, width=None, height=None, tooltips=None, **other_args)¶ Jittered Points, especially for discrete plots or dense plots.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
width (double, optional) – width for jitter, default=0.4
height (double, optional) – height for jitter, default=0.4
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
The jitter geometry is used to create jittered points. The scatterplot is useful for displaying the relationship between two discrete variables. geom_jitter understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
- alphatransparency level of a point
Understands numbers between 0 and 1.
- color (colour)color of a geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- fillcolor to paint shape’s inner points
Is applied only to the points of shapes having inner points.
shape : shape of the point
size : size of the point
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> x = np.random.randint(3, size=100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x': x, 'y': y}) >>> p = ggplot(dat) + geom_jitter(aes(x='x', y='y', color='x'), height=0) >>> p
-
lets_plot.geom_freqpoly(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, tooltips=None, **other_args)¶ Line chart which makes the y value proportional to the number of observed variable values, mapped to x axis.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_freqpoly connects the top points in geom_bar. geom_freqpoly understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
- alphatransparency level of a point
Understands numbers between 0 and 1.
- color (colour)color of a geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- linetypetype of the line
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
size : line width
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> from lets_plot import * >>> N = 100 >>> M = 3 >>> mean = np.zeros(M) >>> mean = np.arange(M) * 5 >>> cov = np.eye(M) >>> X = multivariate_normal.rvs(mean, cov, N) >>> X = X.astype(int) # comment this line to make variables continuous back >>> dat = pd.DataFrame(X) >>> dat = pd.melt(dat) >>> ggplot(dat, aes(x='value')) + geom_freqpoly(size=2)
-
lets_plot.geom_step(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, direction=None, tooltips=None, **other_args)¶ Connects observations in the order, how they appear in the data.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
direction (string, optional) – “hv” or “HV” stands for horizontal then vertical (default); “vh” or “VH” stands for vertical then horizontal
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_step draws steps between the observations in the order of X. geom_step understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
- alphatransparency level of a point
Understands numbers between 0 and 1.
- color (colour)color of a geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- linetypetype of the line
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
size : line width
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> T = 1 >>> N = 1000 >>> t = np.linspace(0, T, N) >>> dt = T / N >>> # brownian motions >>> W1 = np.random.standard_normal(size=N) >>> Wt1 = np.cumsum(W1) * np.sqrt(dt) >>> W2 = np.random.standard_normal(size=N) >>> Wt2 = np.cumsum(W2) * np.sqrt(dt) >>> dat = {} >>> dat['W1'] = Wt1 >>> dat['W2'] = Wt2 >>> dat['t'] = t >>> # transform data via melt function >>> # to produce two trajectories >>> dat = pd.DataFrame(dat) >>> dat = pd.melt(dat, id_vars=['t'], value_vars=['W1', 'W2']) >>> ggplot(dat, aes(x='t', y='value', group='variable')) + geom_step(aes(color='variable'), size=1, alpha=0.7)
-
lets_plot.geom_rect(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, map=None, map_join=None, tooltips=None, **other_args)¶ Draws rectangles
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary, pandas DataFrame or GeoDataFrame (supported shapes MultiPoint, Line, MultiLine, Polygon and MultiPolygon), optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
map (GeoDataFrame (shapes MultiPoint, Line, MultiLine, Polygon and MultiPolygon) or Regions (implicitly invoke limits())) – Bounding boxes of geometries will be drawn.
map_join (str, pair, optional) – Pair of names used to join map coordinates with data. str is allowed only when used with Regions object - map key ‘request’ will be automatically added. first value in pair - column in data second value in pair - column in map
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_rect draws rectangles. geom_rect understands the following aesthetics mappings:
xmin : x-axis value
xmax : x-axis value
ymin : y-axis value
ymax : y-axis value
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- sizelines width
Defines line width
- linetypetype of the line of tile’s border
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
fill : color of geometry filling
Examples
>>> from lets_plot import * >>> ggplot() + geom_rect(aes(xmin=[3], xmax=[4], ymin=[6], ymax=[10]), alpha=0.5, color='black', size=1)
-
lets_plot.geom_segment(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, arrow=None, animation=None, tooltips=None, **other_args)¶ Draws segments
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
arrow (optional) – Specification for arrow head, as created by arrow() function.
animation (type of the animation, optional) – Codes and names: 0 = “none” (default), 1 = “dash”, 2 = “plane”, 3 = “circle”.
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_segment draws segments. geom_segment understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
xend : x-axis value
yend : y-axis value
- alphatransparency level of a point
Understands numbers between 0 and 1.
- color (colour)color of a geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- linetypetype of the line
Codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
size : line width
- speedanimation speed
The number of pixels covered by animation object per second. Default value is 10.
- flowanimation flow
The number of animation objects passing a reference point per second. Default value is 0.1.
Examples
>>> from lets_plot import * >>> ggplot() + geom_segment(aes(x=[3], y=[6], xend=[4], yend=[10]))
-
lets_plot.geom_text(mapping=None, data=None, stat=None, position=None, show_legend=None, sampling=None, map=None, map_join=None, tooltips=None, **other_args)¶ Adds text directly to the plot.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
stat (string, optional) – The statistical transformation to use on the data for this layer, as a string. Supported transformations: “identity” (leaves the data unchanged), “count” (counts number of points with same x-axis coordinate), “bin” (counts number of points with x-axis coordinate in the same bin), “smooth” (performs smoothing - linear default)
position (string, optional) – Position adjustment, either as a string (“identity”, “stack”, “dodge”,…), or the result of a call to a position adjustment function.
map (GeoDataFrame (supported shapes Point and MultiPoint) or Regions (implicitly invoke centroids())) – Data containing coordinates of points.
map_join (str, pair, optional) – Pair of names used to join map coordinates with data. str is allowed only when used with Regions object - map key ‘request’ will be automatically added. first value in pair - column in data second value in pair - column in map
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
Adds text directly to the plot. geom_text understands the following aesthetics mappings:
x : x-axis value
y : y-axis value
label : text to add to plot
- alphatransparency level of a point
Understands numbers between 0 and 1.
- color (colour)color of a geometry
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
size : font size
- family[‘sans’ | ‘serif’ | ‘mono’ | any other like: “Times New Roman”]
Font family. The default is ‘sans’
- fontface[‘plain’ | ‘bold’ | ‘italic’ | ‘bold italic’]
Font style and weight . The default is ‘plain’
- hjust[‘left’, ‘middle’, ‘right’] or number between 0 (‘right’) and 1 (‘left’)
Horizontal text alignment
- vjust[‘bottom’, ‘center’, ‘top’] or number between 0 (‘bottom’) and 1 (‘top’)
Vertical text alignment
angle : Text rotation angle in degrees
Examples
>>> from lets_plot import * >>> ggplot() + geom_text(aes(x=[1], y=[1], label=['Text'], angle=[30], family=['mono']), size = 10)
-
lets_plot.arrow(angle=None, length=None, ends=None, type=None)¶ Describe arrows to add to a line.
- Parameters
angle (numeric) – The angle of the arrow head in degrees (smaller numbers produce narrower, pointier arrows). Essentially describes the width of the arrow head.
length (numeric) – The length of the arrow head (px).
ends ([‘last’ ‘first’ | ‘both’]) – Indicating which ends of the line to draw arrow heads.
type ([‘open’ | ‘closed’]) – Indicating whether the arrow head should be a closed triangle.
- Returns
- Return type
arrow object specification
Examples
>>> from lets_plot import * >>> ggplot() + geom_segment(aes(x=[3], y=[6], xend=[4], yend=[10]), arrow=arrow(type='closed'))
-
lets_plot.lon_lat(lon, lat)¶
-
lets_plot.geom_image(image_data, norm=None, vmin=None, vmax=None)¶ Displays image specified by ndarray with shape (n, m) or (n, m, 3) or (n, m, 4). This geom is not as flexible as geom_raster or geom_tile but vastly superior in the terms of rendering efficiency.
This geom doesn’t understand any aesthetics. It doesn’t support color scales either.
- The following images will be rendered depending on the input array:
N x M - gray-scale
N x M x 3 - RGB
N x M x 4 - RGBA
The type of values in array can be int, uint or float of any size. The value for each component of integer arrays should be in the range [0,255]. The value for each component of float arrays should be in the range [0,1] for RGB or RGBA images.
If gray-scale is encoded as float array then the values will be normalized. If arguments vmin/vmax are specified, they will be used in normalization. Otherwise, min/max value will be computed from the image data.
- Parameters
image_data (numpy.ndarray with shape (n, m) or (n, m, 3) or (n, m, 4)) – Specifies image type, size and pixel values.
norm (bool) – False - disables default scaling of a 2-D float (luminance) input to the (0, 1) range.
vmin, vmax (scalar, optional, default: None) – Uses normalized luminance data. Only applied to gray-scale images encoded as float array.
- Returns
- Return type
geom object specification
Examples
>>> import numpy as np >>> from lets_plot import * >>> image = np.random.choice([0.0, 1.0], [10, 100, 3]) >>> ggplot() + geom_image(image)
-
lets_plot.geom_livemap(mapping=None, data=None, symbol=None, show_legend=None, sampling=None, location=None, zoom=None, projection=None, geodesic=None, tiles=None, map=None, map_join=None, **other_args)¶ Display a live map.
- Parameters
mapping (set of aesthetic mappings created by aes() function.) – Aesthetic mappings describe the way that variables in the data are mapped to plot “aesthetics”.
data (dictionary or pandas DataFrame, optional) – The data to be displayed in this layer. If None, the default, the data is inherited from the plot data as specified in the call to ggplot.
map (GeoDataFrame (supported shapes Point and MultiPoint) or Regions (implicitly invoke centroids())) – Data containing coordinates of points.
map_join (str, pair, optional) – Pair of names used to join map coordinates with data. str is allowed only when used with Regions object - map key ‘request’ will be automatically added. first value in pair - column in data second value in pair - column in map
symbol (string, optional) – The marker used for displaying the data. There are: - ‘point’ for circles of different size and color. - ‘pie’ for pie charts. - ‘bar’ for bar charts.
location (array, optional) – Initial position of the map. If not set, displays the United States. There are [lon1, lat1, lon2, lat2,…, lonN, latN]. - lon1, lon2,…, lonN are longitudes in degrees (positive in the Eastern hemisphere). - lat1, lat2,…, latN are latitudes in degrees (positive in the Northern hemisphere).
zoom (integer, optional) – Zoom of the map in the range 1 - 15.
tiles (string, optional) – Tiles provider, either as a string - URL for a standard raster ZXY tile provider with {z}, {x} and {y} wildcards (e.g. ‘http://my.tile.com/{z}/{x}/{y}.png’) or the result of a call to a maptiles_xxx functions
projection (string, optional) – The map projection. There are: - ‘epsg3857’ for Mercator projection (default). - ‘epsg4326’ for Equirectangular projection.
geodesic (True (default) or False, optional) – Enables geodesic type of all paths and segments
other_args – Other arguments passed on to layer. These are often aesthetics settings, used to set an aesthetic to a fixed value, like color = “red”, fill = “blue”, size = 3, stroke = 2 or shape = 21. They may also be parameters to the paired geom/stat.
- Returns
- Return type
geom object specification
Note
geom_livemap draws map, which can be moved and zoomed. geom_livemap understands the following aesthetics mappings:
- alphatransparency level of a layer
Understands numbers between 0 and 1.
- color (colour)color of a geometry lines
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
- fillcolor of a geometry internals
Can be continuous or discrete. For continuous value this will be a color gradient between two colors.
size : radius for point, pie chart.
sym_x : value order for pie chart and bar chart.
sym_y : value specifying the sector size for pie chart and the heigth for bar chart.
Examples
>>> from lets_plot import * >>> p = ggplot() + geom_livemap() >>> p += ggtitle('Live Map')
-
lets_plot.guide_legend(nrow=None, ncol=None, byrow=None)¶ Legend guide.
- Parameters
nrow (int, optional) – Number of rows in legend’s guide
ncol (int, optional) – Number of columns in legend’s guide
byrow (boolean, optional) – Type of output: by row (default), or by column
- Returns
- Return type
legend guide specification
Note
Legend type guide shows key (i.e., geoms) mapped onto values.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn.datasets import make_blobs >>> X,y = make_blobs(n_samples=1000) >>> dat = {'x': X.T[0], 'y': X.T[1], 'variable': y} >>> dat = pd.DataFrame(dat) >>> colors = {0:'red', 1: 'blue', 2: 'green'} >>> dat['color'] = [colors[variable] for variable in dat['variable']] >>> ggplot(dat, aes(x='x', y='y')) >>> + geom_point(aes(color='color')) >>> + scale_color_manual(list(colors.values()),guide=guide_legend(ncol=3)) >>> + theme(legend_position=[ 0.5,0.5])
-
lets_plot.guide_colorbar(barwidth=None, barheight=None, nbin=None)¶ Continuous color bar guide.
- Parameters
barwidth (value, optional) – Color bar width
barheight (value, optional) – Color bar height
nbin (int, optional) – Number of bins in color bar
- Returns
- Return type
color guide specification
Note
Color bar guide shows continuous color scales mapped onto values. Color bar is available with scale_fill and scale_color.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn.datasets import make_blobs >>> X,y = make_blobs(n_samples=1000) >>> dat = {'x': X.T[0], 'y': X.T[1], 'variable': y} >>> dat = pd.DataFrame(dat) >>> colors = {0:'red', 1: 'blue', 2: 'green'} >>> dat['color'] = [colors[variable] for variable in dat['variable']] >>> ggplot(dat, aes(x='x', y='y')) >>> + geom_point(aes(color='y')) >>> + scale_color_gradient(guide=guide_colorbar(nbin=10,barheight= 8, barwidth=300)) >>> + theme(legend_position='top')
-
lets_plot.gg_image_matrix(image_data_array, *, norm: bool = None, scale=1) → None¶ Display images in a grid. The grid dimensions are determined by shape of the input 2D ndarray.
Elements of the input 2D array are images specified by ndarrays with shape (n, m) or (n, m, 3) or (n, m, 4).
- Parameters
image_data_array (2D numpy.ndarray containing images) – Specifies dimensions of output grid
norm (bool) – False - disables default scaling of a luminance (grayscale) images to the (0, 255) range.
scale (scalar, default: 1) – Specifies magnification factor
- Returns
- Return type
None
Examples
>>> import numpy as np >>> from lets_plot import * >>> image = np.random.choice([0.0, 1.0], [64, 64, 3]) >>> X = np.empty([4, 6], dtype=object) >>> X.fill(image) >>> gg_image_matrix(X)
-
lets_plot.ggtitle(label)¶ Add title to the plot
- Parameters
label (string) – The text for the plot title.
- Returns
- Return type
Plot title specification.
Note
Changes plot title.
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> N = 100 >>> M = 3 >>> mean = np.zeros(M) >>> cov = np.eye(M) >>> X = multivariate_normal.rvs(mean, cov, N) >>> X = X.astype(int) # comment this line to make variables continuous back >>> dat = pd.DataFrame(X) >>> dat = pd.melt(dat) >>> ggplot(dat, aes(x='value', group='variable', fill='variable')) + ... geom_bar(stat='bin', position=position_dodge(width=5.0), width=10, alpha=0.8) + ... ggtitle('Plot title') + xlab('x axis label') + ylab('y axis label')
-
lets_plot.labs(**kwargs)¶ Change plot title, axis labels and legend titles.
- Parameters
kwargs – A list of new names in the form aesthetic=’new name’, e.g. title=’Plot title’ or aes-name=’Scale label’
- Returns
- Return type
Axis label specification.
Note
Change axis labels and legend titles.
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> N = 100 >>> M = 3 >>> mean = np.zeros(M) >>> cov = np.eye(M) >>> X = multivariate_normal.rvs(mean, cov, N) >>> X = X.astype(int) # comment this line to make variables continuous back >>> dat = pd.DataFrame(X) >>> dat = pd.melt(dat) >>> ggplot(dat, aes(x='value', group='variable', fill='variable')) + ... geom_bar(stat='bin', position=position_dodge(width=5.0), width=10, alpha=0.8) + ... labs(title='New plot title', x='New x axis label', y='New y axis label')
-
lets_plot.xlab(label)¶ Add label to the x axis
- Parameters
label (string) – The text for the x axis label
- Returns
- Return type
Axis label specification.
Note
Changes axis label.
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> N = 100 >>> M = 3 >>> mean = np.zeros(M) >>> cov = np.eye(M) >>> X = multivariate_normal.rvs(mean, cov, N) >>> X = X.astype(int) # comment this line to make variables continuous back >>> dat = pd.DataFrame(X) >>> dat = pd.melt(dat) >>> ggplot(dat, aes(x='value', group='variable', fill='variable')) + ... geom_bar(stat='bin', position=position_dodge(width=5.0), width=10, alpha=0.8) + ... ggtitle('Plot title') + xlab('x axis label') + ylab('y axis label')
-
lets_plot.ylab(label)¶ Add label to the y axis
- Parameters
label (string) – The text for the y axis label
- Returns
- Return type
Axis label specification.
Note
Changes axis label.
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> N = 100 >>> M = 3 >>> mean = np.zeros(M) >>> cov = np.eye(M) >>> X = multivariate_normal.rvs(mean, cov, N) >>> X = X.astype(int) # comment this line to make variables continuous back >>> dat = pd.DataFrame(X) >>> dat = pd.melt(dat) >>> ggplot(dat, aes(x='value', group='variable', fill='variable')) + ... geom_bar(stat='bin', position=position_dodge(width=5.0), width=10, alpha=0.8) + ... ggtitle('Plot title') + xlab('x axis label') + ylab('y axis label')
-
lets_plot.ggplot(data=None, mapping=None)¶ Create a new ggplot plot
- Parameters
data (dictionary or pandas DataFrame, optional) – Default dataset to use for the plot. If not specified, must be supplied in each layer added to the plot.
mapping (dictionary, optional) – Default list of aesthetic mappings to use for the plot. If not specified, must be supplied in each layer added to the plot.
- Returns
- Return type
plot specification
Note
ggplot() initializes a ggplot object. It can be used to declare the input data frame for a graphic and to specify the set of plot aesthetics intended to be common throughout all subsequent layers unless specifically overridden. ggplot() is typically used to construct a plot incrementally, using the + operator to add layers to the existing ggplot object. This is advantageous in that the code is explicit about which layers are added and the order in which they are added. For complex graphics with multiple layers, initialization with ggplot() is recommended. There are three common ways to invoke ggplot (see examples below):
- ggplot(dat,aes(x,y)) :
This method is recommended if all layers use the same data and the same set of aesthetics, although this method can also be used to add a layer using data from another data frame.
- ggplot(dat) :
This method specifies the default data frame to use for the plot, but no aesthetics are defined up front. This is useful when one data frame is used predominantly as layers are added, but the aesthetics may vary from one layer to another.
- ggplot() :
This method initializes a skeleton ggplot object which is fleshed out as layers are added. This method is useful when multiple data frames are used to produce different layers, as is often the case in complex graphics.
ggplot() with no layers defined will produce an error message: “No layers in plot”
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> x = np.random.uniform(-1, 1, size=100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(100)] >>> # three ways to invoke ggplot, producing the same output: >>> # (1) >>> ggplot(dat, aes(x='x', y='y')) + layer() >>> # (2) >>> ggplot(dat) + layer() >>> # (3) >>> ggplot() + layer('point', 'identity', dat)
-
lets_plot.ggsize(width, height)¶ Specifies overall size of plot
- Parameters
width (number) – Width of plot in px.
height (number) – Height of plot in px.
- Returns
- Return type
plot size specification
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> x = np.arange(100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x':x, 'y':y}) >>> ggplot(dat) + geom_line(aes('x','y')) + ggsize(600, 120)
-
class
lets_plot.GGBunch¶ Bases:
lets_plot.plot.core.FeatureSpecCollection of plots created by ggplot function. Use method add_plot() to add plot to ‘bunch’. Each plot can have arbitrary location and size. Use show() to draw all plots in bunch.
Examples
>>> import numpy as np >>> import pandas as pd >>> from lets_plot import * >>> x = np.arange(100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x':x, 'y':y}) >>> g = ggplot(dat, mapping=aes('x', 'y')) + ggsize(150, 150) >>> bunch = GGBunch() >>> bunch.add_plot(g + geom_point(), 0, 0) >>> bunch.add_plot(g + geom_histogram(bins=4), 150, 0) >>> bunch.add_plot(g + geom_line(), 0, 150, 200, 100) >>> bunch.show()
-
add_plot(plot_spec: lets_plot.plot.core.PlotSpec, x, y, width=None, height=None)¶ Adds plot to ‘bunch’
- Parameters
plot_spec (value of ggplot()) – Plot specification created by ggplot() function
x (number) – x-coordinate of plot origin in px.
y (number) – y-coordinate of plot origin in px.
width (number) – Width of plot in px.
height – Height of plot in px.
-
as_dict()¶
-
show()¶ Draw all plots currently in this ‘bunch’
-
-
lets_plot.position_dodge(width=None)¶ Adjust position by dodging overlaps to the side
- Parameters
width – Dodging width, when different to the width of the individual elements. This is useful when you want to align narrow geoms with wider geoms.
- Returns
- Return type
geom object position specification
Note
Adjust position by dodging overlaps to the side.
Examples
>>> import numpy as np >>> import pandas as pd >>> from scipy.stats import multivariate_normal >>> N = 100 >>> M = 3 >>> mean = np.zeros(M) >>> cov = np.eye(M) >>> X = multivariate_normal.rvs(mean, cov, N) >>> X = X.astype(int) # comment this line to make variables continuous back >>> dat = pd.DataFrame(X) >>> dat = pd.melt(dat) >>> ggplot(dat, aes(x='value', group='variable', fill='variable')) + ... geom_bar(stat='bin', position=position_dodge(width=5.0), width=10, alpha=0.8)
-
lets_plot.position_jitter(width=None, height=None)¶ Adjust position by assigning random noise to points. Better for discrete values
- Parameters
width – Jittering width
height – Jittering height
- Returns
- Return type
geom object position specification
Note
Adjust position by dodging overlaps to the side.
Examples
>>> import numpy as np >>> from random import randint >>> N = 100 >>> x = np.array([['a', 'b', 'c'] for i in range(N)]).flatten() >>> y = np.array([randint(0, 2) for i in range(3 * N)]) >>> ggplot(mapping=aes(x, y)) + geom_point(position=position_jitter(width=.2, height=.2))
-
lets_plot.position_nudge(x=None, y=None)¶ Adjust position by nudging a given offset
- Parameters
x – Nudging width
y – Nudging height
- Returns
- Return type
geom object position specification
Note
Adjust position by dodging overlaps to the side.
Examples
>>> x = [1, 2, 3] >>> y = [1, 2, 3] >>> ggplot(mapping=aes(x, y)) + geom_point() + geom_point(position=position_nudge(y=-0.2), color='orange')
-
lets_plot.position_jitterdodge(dodge_width=None, jitter_width=None, jitter_height=None)¶ This is primarily used for aligning points generated through geom_point() with dodged boxplots (e.g., a geom_boxplot() with a fill aesthetic supplied).
- Parameters
dodge_width – Bin width
jitter_width – jittering width
jitter_height – jittering height
- Returns
- Return type
geom object position specification
Note
Adjust position by dodging overlaps to the side.
Examples
>>> import pandas as pd >>> from lets_plot import * >>> mpg_url = 'https://vincentarelbundock.github.io/Rdatasets/csv/ggplot2/mpg.csv' >>> mpg = pd.read_csv(mpg_url) >>> p = ggplot(mpg, aes('cyl', 'hwy',group='drv',fill='drv')) >>> p += scale_color_discrete() + scale_fill_discrete() >>> p + geom_boxplot(outlier_size=0) + geom_point(position='jitterdodge', shape=21, color='black')
-
lets_plot.sampling_random(n, seed=None)¶
-
lets_plot.sampling_random_stratified(n, seed=None, min_subsample=None)¶
-
lets_plot.sampling_pick(n)¶
-
lets_plot.sampling_systematic(n)¶
-
lets_plot.sampling_group_random(n, seed=None)¶
-
lets_plot.sampling_group_systematic(n)¶
-
lets_plot.sampling_vertex_vw(n)¶
-
lets_plot.sampling_vertex_dp(n)¶
-
lets_plot.scale_shape(solid=True, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Scale for shapes
- Parameters
solid (boolean) – Are the shapes solid (default) True, or hollow (False)?
name (string) – The name of the scale - used as the axis label or the legend title
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Scale for shapes. A continuous variable cannot be mapped to shape.
Examples
>>> import numpy as np >>> import pandas as pd >>> x = np.random.uniform(-1, 1, size=100) >>> y = np.random.normal(size=100) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(100)] >>> ggplot(dat, aes(x='x', y='y', shape='class')) + geom_point(size=5) + scale_shape(solid=False)
-
lets_plot.scale_x_discrete(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None, reverse=None)¶ Discrete position scales (x)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
reverse (boolean) – When True the scale reversed.
- Returns
- Return type
scale specification
Note
Discrete position scales.
Examples
>>> import numpy as np >>> import pandas as pd >>> N = 10000 >>> x = np.random.uniform(-4, 4, size=N) >>> x = x.astype(int) >>> y = np.random.normal(size=N) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(N)] >>> breaks = [-3, -2, -1, 0, 1, 2, 3] >>> labels = ['-3', '-2', '-1', '0', '1', '2', '3'] >>> ggplot(dat, aes('x', group='class')) + geom_bar(stat='count') + ... scale_x_discrete(name='discretised x', breaks=breaks, labels=labels)
-
lets_plot.scale_y_discrete(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None, reverse=None)¶ Discrete position scales (y)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
reverse (boolean) – When True the scale reversed.
- Returns
- Return type
scale specification
Note
Discrete position scales.
Examples
>>> import numpy as np >>> import pandas as pd >>> N = 10000 >>> x = np.random.uniform(-4, 4, size=N) >>> x = x.astype(int) >>> y = np.random.normal(size=N) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(N)] >>> breaks = [-3, -2, -1, 0, 1, 2, 3] >>> labels = ['-3', '-2', '-1', '0', '1', '2', '3'] >>> y_breaks = [1500, 3000] >>> y_labels = ['one', 'two'] >>> ggplot(dat, aes('x', 'y', group='class')) + geom_bar(stat='count') + ... scale_y_discrete(breaks=y_breaks, labels=y_labels)
-
lets_plot.scale_x_discrete_reversed(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Reversed discrete position scales (x)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
- Returns
- Return type
scale specification
Note
Reversed discrete position scales.
-
lets_plot.scale_y_discrete_reversed(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Reversed discrete position scales (y)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
- Returns
- Return type
scale specification
Note
Reversed discrete position scales.
-
lets_plot.scale_x_continuous(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None, trans=None)¶ Continuous position scales (x)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
na_value – Missing values will be replaced with this value.
trans – Name of built-in transformation. (‘identity’, ‘log10’)
- Returns
- Return type
scale specification
Note
Continuous position scales.
Examples
>>> import numpy as np >>> import pandas as pd >>> N = 10000 >>> x = np.random.uniform(-4, 4, size=N) >>> x = x.astype(int) >>> y = np.random.normal(size=N) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(N)] >>> breaks = [-3, -2, -1, 0, 1, 2, 3] >>> labels = ['-3', '-2', '-1', '0', '1', '2', '3'] >>> ggplot(dat, aes('x', group='class')) + geom_bar(stat='count') + ... scale_x_continuous(name='discretised x', breaks=breaks, labels=labels)
-
lets_plot.scale_y_continuous(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None, trans=None)¶ Continuous position scales (y)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
trans – Name of built-in transformation. (‘identity’, ‘log10’)
- Returns
- Return type
scale specification
Note
Continuous position scales.
Examples
>>> import numpy as np >>> import pandas as pd >>> N = 10000 >>> x = np.random.uniform(-4, 4, size=N) >>> x = x.astype(int) >>> y = np.random.normal(size=N) >>> dat = pd.DataFrame({'x': x, 'y': 25 * x ** 2 + y}) >>> dat['class'] = ['0' if dat['x'][i] < 0 else '1' for i in range(N)] >>> breaks = [-3, -2, -1, 0, 1, 2, 3] >>> labels = ['-3', '-2', '-1', '0', '1', '2', '3'] >>> y_breaks = [1500, 3000] >>> y_labels = ['one', 'two'] >>> ggplot(dat, aes('x', 'y', group='class')) + geom_bar(stat='count') + ... scale_y_continuous(breaks=y_breaks, labels=y_labels)
-
lets_plot.scale_x_log10(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Continuous position scales (x) where trans=’log10’
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
na_value – Missing values will be replaced with this value.
- Returns
- Return type
scale specification
Note
Continuous position scales.
Examples
>>> import pandas as pd >>> N = 21 >>> x = [v for v in range(N)] >>> y0 = [pow(10, v / 10.) for v in range(N)] >>> y1 = [v * 5 for v in range(N)] >>> formula = ['10^(x/10)'] * N + ['5*x'] * N >>> data = dict(x=x * 2, y=y0 + y1, formula=formula) >>> ### Linear scales (default) >>> p = ggplot(data) + geom_point(aes('x', 'y', color='formula', size='formula')) + ... scale_size_manual(values=[7, 3]) >>> ### Log10 scale on Y axis >>> p + scale_y_log10() >>> ### Log10 scale on both axis >>> p + scale_y_log10() + scale_x_log10()
-
lets_plot.scale_y_log10(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Continuous position scales (y) where trans=’log10’
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
na_value – Missing values will be replaced with this value.
- Returns
- Return type
scale specification
Note
Continuous position scales.
Examples
>>> import pandas as pd >>> N = 21 >>> x = [v for v in range(N)] >>> y0 = [pow(10, v / 10.) for v in range(N)] >>> y1 = [v * 5 for v in range(N)] >>> formula = ['10^(x/10)'] * N + ['5*x'] * N >>> data = dict(x=x * 2, y=y0 + y1, formula=formula) >>> ### Linear scales (default) >>> p = ggplot(data) + geom_point(aes('x', 'y', color='formula', size='formula')) + ... scale_size_manual(values=[7, 3]) >>> ### Log10 scale on Y axis >>> p + scale_y_log10() >>> ### Log10 scale on both axis >>> p + scale_y_log10() + scale_x_log10()
-
lets_plot.scale_x_reverse(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Continuous position scales (x) where trans=’reverse’
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
na_value – Missing values will be replaced with this value.
- Returns
- Return type
scale specification
Note
Continuous position scales.
Examples
>>> import pandas as pd >>> N = 21 >>> x = [v for v in range(N)] >>> y0 = [pow(10, v / 10.) for v in range(N)] >>> y1 = [v * 5 for v in range(N)] >>> formula = ['10^(x/10)'] * N + ['5*x'] * N >>> data = dict(x=x * 2, y=y0 + y1, formula=formula) >>> ### Linear scales (default) >>> p = ggplot(data) + geom_point(aes('x', 'y', color='formula', size='formula')) + ... scale_size_manual(values=[7, 3]) >>> ### reverse scale on X axis >>> p + scale_x_reverse()
-
lets_plot.scale_y_reverse(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Continuous position scales (y) where trans=’reverse’
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
na_value – Missing values will be replaced with this value.
- Returns
- Return type
scale specification
Note
Continuous position scales.
Examples
>>> import pandas as pd >>> N = 21 >>> x = [v for v in range(N)] >>> y0 = [pow(10, v / 10.) for v in range(N)] >>> y1 = [v * 5 for v in range(N)] >>> formula = ['10^(x/10)'] * N + ['5*x'] * N >>> data = dict(x=x * 2, y=y0 + y1, formula=formula) >>> ### Linear scales (default) >>> p = ggplot(data) + geom_point(aes('x', 'y', color='formula', size='formula')) + ... scale_size_manual(values=[7, 3]) >>> ### reverse scale on Y axis >>> p + scale_y_reverse()
-
lets_plot.scale_color_manual(values, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Create your own discrete scale for color aesthetic
- Parameters
values (list of strings) – A set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Create your own discrete scale for color aesthetic. Values are strings, encoding colors.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> X = iris.data >>> y = iris.target >>> # (1) Split data >>> from sklearn.cross_validation import train_test_split >>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) >>> # (2) Scale data >>> from sklearn.preprocessing import StandardScaler >>> sc = StandardScaler() >>> sc.fit(X_train) >>> X_train = sc.transform(X_train) >>> X_test = sc.transform(X_test) >>> # (3) Fit model >>> n_components = 2 >>> from sklearn.decomposition import KernelPCA >>> kpca = KernelPCA(n_components=n_components, kernel="rbf", fit_inverse_transform=True, gamma=1.0) >>> kpca.fit(X_train) >>> X_reduced = kpca.fit_transform(X_train) >>> # (4) Kernel PCA reduction: plot >>> dat = dict({'PC1': X_reduced[:, 0], 'PC2': X_reduced[:, 1], 'target': y_train}) >>> ggplot(dat, aes('PC1', 'PC2')) + geom_point(aes(color='target'), size=3) + ... scale_color_manual(values=['red', 'blue', 'green'])
-
lets_plot.scale_fill_manual(values, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Create your own discrete scale for fill aesthetic
- Parameters
values (list of strings) – A set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Create your own discrete scale for fill aesthetic. Values are strings, encoding filling colors.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> X = iris.data >>> y = iris.target >>> # (1) Split data >>> from sklearn.cross_validation import train_test_split >>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) >>> # (2) Scale data >>> from sklearn.preprocessing import StandardScaler >>> sc = StandardScaler() >>> sc.fit(X_train) >>> X_train = sc.transform(X_train) >>> X_test = sc.transform(X_test) >>> # (3) Fit model >>> n_components = 2 >>> from sklearn.decomposition import KernelPCA >>> kpca = KernelPCA(n_components=n_components, kernel="rbf", fit_inverse_transform=True, gamma=1.0) >>> kpca.fit(X_train) >>> X_reduced = kpca.fit_transform(X_train) >>> # (4) Kernel PCA reduction: plot >>> dat = dict({'PC1': X_reduced[:, 0], 'PC2': X_reduced[:, 1], 'target': y_train}) >>> ggplot(dat, aes('PC1', 'PC2')) + geom_point(aes(color='target', fill='target'), size=3, shape=21) + ... scale_color_manual(values=['black', 'black', 'black']) + ... scale_fill_manual(values=['red', 'blue', 'green'])
-
lets_plot.scale_size_manual(values, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Create your own discrete scale for size aesthetic
- Parameters
values (list of strings) – A set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Create your own discrete scale for size aesthetic. Values are numbers, defining sizes.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> X = iris.data >>> y = iris.target >>> # (1) Split data >>> from sklearn.cross_validation import train_test_split >>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) >>> # (2) Scale data >>> from sklearn.preprocessing import StandardScaler >>> sc = StandardScaler() >>> sc.fit(X_train) >>> X_train = sc.transform(X_train) >>> X_test = sc.transform(X_test) >>> # (3) Fit model >>> n_components = 2 >>> from sklearn.decomposition import KernelPCA >>> kpca = KernelPCA(n_components=n_components, kernel="rbf", fit_inverse_transform=True, gamma=1.0) >>> kpca.fit(X_train) >>> X_reduced = kpca.fit_transform(X_train) >>> # (4) Kernel PCA reduction: plot >>> dat = dict({'PC1': X_reduced[:, 0], 'PC2': X_reduced[:, 1], 'target': y_train}) >>> ggplot(dat, aes('PC1', 'PC2')) + geom_point(aes(color='target', size='target')) + ... scale_color_manual(values=['red', 'blue', 'green']) + ... scale_size_manual(values=[2, 4, 6])
-
lets_plot.scale_shape_manual(values, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Create your own discrete scale for shape aesthetic
- Parameters
values (list of strings) – A set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Create your own discrete scale for size aesthetic. Values are numbers, encoding shapes.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> X = iris.data >>> y = iris.target >>> # (1) Split data >>> from sklearn.cross_validation import train_test_split >>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) >>> # (2) Scale data >>> from sklearn.preprocessing import StandardScaler >>> sc = StandardScaler() >>> sc.fit(X_train) >>> X_train = sc.transform(X_train) >>> X_test = sc.transform(X_test) >>> # (3) Fit model >>> n_components = 2 >>> from sklearn.decomposition import KernelPCA >>> kpca = KernelPCA(n_components=n_components, kernel="rbf", fit_inverse_transform=True, gamma=1.0) >>> kpca.fit(X_train) >>> X_reduced = kpca.fit_transform(X_train) >>> # (4) Kernel PCA reduction: plot >>> dat = dict({'PC1': X_reduced[:, 0], 'PC2': X_reduced[:, 1], 'target': y_train, 'tgt': y_train.astype(str)}) >>> ggplot(dat, aes('PC1', 'PC2')) + geom_point(aes(color='target', shape='tgt'), size=3) + ... scale_color_manual(values=['red', 'blue', 'green']) + ... scale_shape_manual(values=[0, 1, 2])
-
lets_plot.scale_linetype_manual(values, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Create your own discrete scale for line type aesthetic
- Parameters
values (list of strings) – A set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Create your own discrete scale for line type aesthetic. Values are strings or numbers, encoding linetypes. Available codes and names: 0 = “blank”, 1 = “solid”, 2 = “dashed”, 3 = “dotted”, 4 = “dotdash”, 5 = “longdash”, 6 = “twodash”
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> X = iris.data >>> y = iris.target >>> # (1) Split data >>> from sklearn.cross_validation import train_test_split >>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) >>> # (2) Scale data >>> from sklearn.preprocessing import StandardScaler >>> sc = StandardScaler() >>> sc.fit(X_train) >>> X_train = sc.transform(X_train) >>> X_test = sc.transform(X_test) >>> # (3) Fit model >>> n_components = 2 >>> from sklearn.decomposition import KernelPCA >>> kpca = KernelPCA(n_components=n_components, kernel="rbf", fit_inverse_transform=True, gamma=1.0) >>> kpca.fit(X_train) >>> X_reduced = kpca.fit_transform(X_train) >>> # (4) Kernel PCA reduction: plot >>> dat = dict({'PC1': X_reduced[:, 0], 'PC2': X_reduced[:, 1], 'target': y_train, 'tgt': y_train.astype(str)}) >>> ggplot(dat, aes('PC1', 'PC2')) + geom_line(aes(color='target', linetype='tgt'), size=1) + ... scale_color_manual(values=['red', 'blue', 'green']) + ... scale_linetype_manual(values=['dotted', 'solid', 'dashed'])
-
lets_plot.scale_alpha_manual(values, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Create your own discrete scale for alpha (transparency) aesthetic
- Parameters
values (list of strings) – A set of aesthetic values to map data values to. If this is a named vector, then the values will be matched based on the names. If unnamed, values will be matched in order (usually alphabetical) with the limits of the scale.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Create your own discrete scale for alpha (transparency) aesthetic. Values should be taken from [0,1] interval.
Examples
>>> import numpy as np >>> import pandas as pd >>> from sklearn import datasets >>> iris = datasets.load_iris() >>> X = iris.data >>> y = iris.target >>> # (1) Split data >>> from sklearn.cross_validation import train_test_split >>> X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3) >>> # (2) Scale data >>> from sklearn.preprocessing import StandardScaler >>> sc = StandardScaler() >>> sc.fit(X_train) >>> X_train = sc.transform(X_train) >>> X_test = sc.transform(X_test) >>> # (3) Fit model >>> n_components = 2 >>> from sklearn.decomposition import KernelPCA >>> kpca = KernelPCA(n_components=n_components, kernel="rbf", fit_inverse_transform=True, gamma=1.0) >>> kpca.fit(X_train) >>> X_reduced = kpca.fit_transform(X_train) >>> # (4) Kernel PCA reduction: plot >>> dat = dict({'PC1': X_reduced[:, 0], 'PC2': X_reduced[:, 1], 'target': y_train, 'tgt': y_train.astype(str)}) >>> ggplot(dat, aes('PC1', 'PC2')) + geom_point(aes(color='target', alpha='target'), size=3) + ... scale_color_manual(values=['red', 'blue', 'green']) + ... scale_alpha_manual(values=[0.2, 0.5, 0.9])
-
lets_plot.scale_fill_gradient(low=None, high=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Defines smooth color gradient between two colors for fill aesthetic
- Parameters
low (string) – Color for low end of gradient
high (string) – Color for high end of gradient
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines smooth gradient between two colors (defined by low and high) for filling color.
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_fill_gradient(low='green', high='red')
-
lets_plot.scale_fill_continuous(low=None, high=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Defines smooth color gradient between two colors for fill aesthetic
- Parameters
low (string) – Color for low end of gradient
high (string) – Color for high end of gradient
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
- Returns
- Return type
scale specification
Note
Defines smooth gradient between two colors (defined by low and high) for filling color.
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_fill_continuous(low='green', high='red')
-
lets_plot.scale_color_gradient(low=None, high=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Defines smooth color gradient between two colors for color aesthetic
- Parameters
low (string) – Color for low end of gradient
high (string) – Color for high end of gradient
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines smooth gradient between two colors (defined by low and high) for color aesthetic.
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x', color='x'), width=1.05, size=2) + ... scale_color_gradient(low='green', high='red')
-
lets_plot.scale_color_continuous(low=None, high=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Defines smooth color gradient between two colors for color aesthetic
- Parameters
low (string) – Color for low end of gradient
high (string) – Color for high end of gradient
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
- Returns
- Return type
scale specification
Note
Defines smooth gradient between two colors (defined by low and high) for color aesthetic.
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x', color='x'), width=1.05, size=2) + ... scale_color_continuous(low='green', high='red')
-
lets_plot.scale_fill_gradient2(low=None, mid=None, high=None, midpoint=0, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Defines diverging color gradient for fill aesthetic
- Parameters
low (string) – Color for low end of gradient
mid (string) – Color for mid point
high (string) – Color for high end of gradient
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines diverging color gradient for filling color. Default mid point is set to white color.
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_fill_gradient2(low='green', high='red')
-
lets_plot.scale_color_gradient2(low=None, mid=None, high=None, midpoint=0, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Defines diverging color gradient for color aesthetic
- Parameters
low (string) – Color for low end of gradient
mid (string) – Color for mid point
high (string) – Color for high end of gradient
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines diverging color gradient for color aesthetic. Default mid point is set to white color.
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_color_gradient2(low='green', high='red')
-
lets_plot.scale_fill_hue(h=None, c=None, l=None, h_start=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Qualitative color scale with evenly spaced hues for fill aesthetic
- Parameters
h (list of two numerics) – Range of hues, in [0,360]
c (numeric) – Chroma (intensity of color), maximum value varies depending on.
l (numeric) – Luminance (lightness), in [0,100]
direction (numeric) – Direction to travel around the color wheel, 1 = clockwise (default), -1=counter-clockwise
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines qualitative color scale with evenly spaced hues for filling color aesthetic
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_fill_hue(c=50, l=80, h=[0, 50])
-
lets_plot.scale_fill_discrete(h=None, c=None, l=None, h_start=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Qualitative color scale with evenly spaced hues for fill aesthetic
- Parameters
h (list of two numerics) – Range of hues, in [0,360]
c (numeric) – Chroma (intensity of color), maximum value varies depending on.
l (numeric) – Luminance (lightness), in [0,100]
direction (numeric) – Direction to travel around the color wheel, 1 = clockwise (default), -1=counter-clockwise
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines qualitative color scale with evenly spaced hues for filling color aesthetic
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_fill_discrete(c=50, l=80, h=[0, 50])
-
lets_plot.scale_color_hue(h=None, c=None, l=None, h_start=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Qualitative color scale with evenly spaced hues for color aesthetic
- Parameters
h (list of two numerics) – Range of hues, in [0,360]
c (numeric) – Chroma (intensity of color), maximum value varies depending on.
l (numeric) – Luminance (lightness), in [0,100]
direction (numeric) – Direction to travel around the color wheel, 1 = clockwise (default), -1=counter-clockwise
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines qualitative color scale with evenly spaced hues for color aesthetic
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x', color='x'), width=1.05, size=2) + ... scale_color_hue(c=20, l=90)
-
lets_plot.scale_color_discrete(h=None, c=None, l=None, h_start=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None)¶ Qualitative color scale with evenly spaced hues for color aesthetic
- Parameters
h (list of two numerics) – Range of hues, in [0,360]
c (numeric) – Chroma (intensity of color), maximum value varies depending on.
l (numeric) – Luminance (lightness), in [0,100]
direction (numeric) – Direction to travel around the color wheel, 1 = clockwise (default), -1=counter-clockwise
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines qualitative color scale with evenly spaced hues for color aesthetic
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x', color='x'), width=1.05, size=2) + ... scale_color_discrete(c=20, l=90)
-
lets_plot.scale_fill_grey(start=None, end=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Sequential grey color scale for fill aesthetic. The palette is computed using HSV (hue, saturation, value) color model.
- Parameters
start (numeric) – Gray value at low end of palette in range [0,1]
end (numeric) – Gray value at high end of palette in range [0,1]
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines sequential grey color scale for filling color aesthetic
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_fill_grey(start=0.5, end=0.1)
-
lets_plot.scale_color_grey(start=None, end=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Sequential grey color scale for color aesthetic. The palette is computed using HSV (hue, saturation, value) color model.
- Parameters
start (numeric) – Gray value at low end of palette in range [0,1]
end (numeric) – Gray value at high end of palette in range [0,1]
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines sequential grey color scale for color aesthetic
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x', color='x'), width=1.05, size=2) + ... scale_color_grey(start=0.5, end=0.1)
-
lets_plot.scale_fill_brewer(type=None, palette=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Sequential, diverging and qualitative color scales from colorbrewer.org for fill aesthetic. Color schemes provided are particularly suited to display discrete values (levels of factors) on a map.
- Parameters
type (string) – One of seq (sequential), div (diverging) or qual (qualitative) types of scales.
palette (string or number) – If a string, will use that named palette. If a number, will index into the list of palettes of appropriate type.
direction (numeric) – Sets the order of colors in the scale. If 1, the default, colors are as output by brewer.pal. If -1, the order of colors is reversed.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines sequential, diverging and qualitative color scales from colorbrewer.org for filling color aesthetic. ColorBrewer provides sequential, diverging and qualitative color schemes which are particularly suited and tested to display discrete values (levels of a factor) on a map. ggplot2 can use those colors in discrete scales. It also allows to smoothly interpolate 6 colors from any palette to a continuous scale (6 colors per palette gives nice gradients; more results in more saturated colors which do not look as good). However, the original color schemes (particularly the qualitative ones) were not intended for this and the perceptual result is left to the appreciation of the user. See colorbrewer2.org for more information.
- Palettes:
- Diverging :
BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral
- Qualitative :
Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3
- Sequential :
Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu, YlOrBr, YlOrRd
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x'), width=1.05) + ... scale_fill_brewer(type='seq', palette='Oranges')
-
lets_plot.scale_color_brewer(type=None, palette=None, direction=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Sequential, diverging and qualitative color scales from colorbrewer.org for color aesthetic. Color schemes provided are particularly suited to display discrete values (levels of factors) on a map.
- Parameters
type (string) – One of seq (sequential), div (diverging) or qual (qualitative) types of scales.
palette (string or number) – If a string, will use that named palette. If a number, will index into the list of palettes of appropriate type.
direction (numeric) – Sets the order of colors in the scale. If 1, the default, colors are as output by brewer.pal. If -1, the order of colors is reversed.
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
- Returns
- Return type
scale specification
Note
Defines sequential, diverging and qualitative color scales from colorbrewer.org for color aesthetic. ColorBrewer provides sequential, diverging and qualitative color schemes which are particularly suited and tested to display discrete values (levels of a factor) on a map. ggplot2 can use those colors in discrete scales. It also allows to smoothly interpolate 6 colors from any palette to a continuous scale (6 colors per palette gives nice gradients; more results in more saturated colors which do not look as good). However, the original color schemes (particularly the qualitative ones) were not intended for this and the perceptual result is left to the appreciation of the user. See colorbrewer2.org for more information.
- Palettes:
- Diverging :
BrBG, PiYG, PRGn, PuOr, RdBu, RdGy, RdYlBu, RdYlGn, Spectral
- Qualitative :
Accent, Dark2, Paired, Pastel1, Pastel2, Set1, Set2, Set3
- Sequential :
Blues, BuGn, BuPu, GnBu, Greens, Greys, Oranges, OrRd, PuBu, PuBuGn, PuRd, Purples, RdPu, Reds, YlGn, YlGnBu, YlOrBr, YlOrRd
Examples
>>> dat = {'x': [v for v in range(-16, 16)]} >>> ggplot(dat) + geom_tile(aes('x', fill='x', color='x'), width=1.05, size=2) + ... scale_color_brewer(type='seq', palette='Oranges')
-
lets_plot.scale_x_datetime(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Continuous position scale (x)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
na_value – Missing values will be replaced with this value.
- Returns
- Return type
scale specification
Note
Continuous position scales.
Examples
>>> import pandas as pd >>> from datetime import datetime >>> economics_url = 'https://vincentarelbundock.github.io/Rdatasets/csv/ggplot2/economics.csv' >>> economics = pd.read_csv(economics_url) >>> economics['date'] = pd.to_datetime(economics['date']) >>> start = datetime(2000, 1, 1) >>> economics = economics.loc[economics['date'] >= start] >>> ggplot(economics, aes('date', 'unemploy')) + ... geom_step() + scale_x_datetime()
-
lets_plot.scale_y_datetime(name=None, breaks=None, labels=None, limits=None, expand=None, na_value=None)¶ Continuous position scale (y)
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list of numerics) – A numeric vector of length two providing limits of the scale.
expand – A numeric vector of length two giving multiplicative and additive expansion constants.
na_value – Missing values will be replaced with this value.
- Returns
- Return type
scale specification
Note
Continuous position scales.
-
lets_plot.scale_alpha(range=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Scales for alpha
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
na_value – Missing values will be replaced with this value.
range (list of numerics of length 2) – The range of the mapped aesthetics result.
- Returns
- Return type
scale specification
Examples
>>> import numpy as np >>> data = {} >>> np.random.seed(43) >>> data['x'] = np.append(np.random.normal(0, 1, 1000), np.random.normal(3, 1, 500)) >>> data['y'] = np.append(np.random.normal(0, 1, 1000), np.random.normal(3, 1, 500)) >>> q = ggplot(data, aes('x', 'y')) >>> q + geom_point(aes(alpha='..density..'), stat='density2d', contour=False, n=30) + ... scale_alpha(range=[0.5, 1])
-
lets_plot.scale_size(range=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Scales for size
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
na_value – Missing values will be replaced with this value.
range (list of numerics of length 2) – The range of the mapped aesthetics result.
- Returns
- Return type
scale specification
Examples
>>> import numpy as np >>> data = {} >>> np.random.seed(43) >>> data['x'] = np.append(np.random.normal(0, 1, 1000), np.random.normal(3, 1, 500)) >>> data['y'] = np.append(np.random.normal(0, 1, 1000), np.random.normal(3, 1, 500)) >>> q = ggplot(data, aes('x', 'y')) >>> q + geom_point(aes(alpha='..density..'), stat='density2d', contour=False, n=30) + ... scale_size(range=[1, 6])
-
lets_plot.scale_size_area(max_size=None, name=None, breaks=None, labels=None, limits=None, na_value=None, guide=None, trans=None)¶ Continuous scales for size that maps 0 to 0
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title. If None, the default, the name of the scale is taken from the first mapping used for that aesthetic.
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – A vector specifying the data range for the scale. and the default order of their display in guides.
na_value – Missing values will be replaced with this value.
max_size (numeric) – The max size that is mapped to.
- Returns
- Return type
scale specification
Note
This method maps 0 data to 0 size. Useful in some stats such as count.
Examples
>>> import numpy as np >>> data = {} >>> np.random.seed(43) >>> data['x'] = np.append(np.random.normal(0, 1, 1000), np.random.normal(3, 1, 500)) >>> data['y'] = np.append(np.random.normal(0, 1, 1000), np.random.normal(3, 1, 500)) >>> q = ggplot(data, aes('x', 'y')) >>> q + geom_point(aes(alpha='..density..'), stat='density2d', contour=False, n=30) + ... scale_size_area(max_size=10)
-
lets_plot.lims(x, y)¶
-
lets_plot.xlim(*args)¶
-
lets_plot.ylim(*args)¶
-
lets_plot.scale_color_identity(name=None, breaks=None, labels=None, limits=None, na_value=None, guide='none')¶ Use this scale when your data has already been scaled. I.e. it already represents aesthetic values that ggplot2 can handle directly. This will not produce a legend unless you also supply the breaks and labels.
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
guide – Guide to use for this scale. Defaults to “none”.
- Returns
- Return type
scale specification
Note
- Input data expected: list of strings containing
names of colors (i.e. ‘green’)
hex codes of colors (i.e ‘x00ff00’)
css colors (i.e ‘rgb(0,255,0)’)
Examples
>>> import pandas as pd >>> from lets_plot import * >>> x = [0, 1, 2] >>> y = x >>> c = ['red', 'green', 'blue'] >>> dat = pd.DataFrame({'x': x, 'y': y, 'c': c}) >>> ggplot(dat, aes('x', 'y', color='c')) + geom_point(size=15) + scale_color_identity()
-
lets_plot.scale_fill_identity(name=None, breaks=None, labels=None, limits=None, na_value=None, guide='none')¶ Use this scale when your data has already been scaled. I.e. it already represents aesthetic values that ggplot2 can handle directly. This will not produce a legend unless you also supply the breaks and labels.
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
guide – Guide to use for this scale. Defaults to “none”.
- Returns
- Return type
scale specification
Note
- Input data expected: list of strings containing
names of colors (i.e. ‘green’)
hex codes of colors (i.e ‘x00ff00’)
css colors (i.e ‘rgb(0,255,0)’)
Examples
>>> import pandas as pd >>> from lets_plot import * >>> x = [0, 1, 2] >>> y = x >>> c = ['red', 'green', 'blue'] >>> dat = pd.DataFrame({'x': x, 'y': y, 'c': c}) >>> ggplot(dat, aes('x', 'y', fill='c')) + geom_tile() + scale_fill_identity()
-
lets_plot.scale_shape_identity(name=None, breaks=None, labels=None, limits=None, na_value=None, guide='none')¶ Use this scale when your data has already been scaled. I.e. it already represents aesthetic values that ggplot2 can handle directly. This will not produce a legend unless you also supply the breaks and labels.
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
guide – Guide to use for this scale. Defaults to “none”.
- Returns
- Return type
scale specification
Note
Input data expected: numetic codes of shapes.
Examples
>>> import pandas as pd >>> from lets_plot import * >>> x = range(7) >>> y = x >>> s = range(7) >>> dat = pd.DataFrame({'x': x, 'y': y, 's': s}) >>> ggplot(dat, aes('x', 'y', shape='s')) + geom_point(size=5) + scale_shape_identity()
-
lets_plot.scale_linetype_identity(name=None, breaks=None, labels=None, limits=None, na_value=None, guide='none')¶ Use this scale when your data has already been scaled. I.e. it already represents aesthetic values that ggplot2 can handle directly. This will not produce a legend unless you also supply the breaks and labels.
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
guide – Guide to use for this scale. Defaults to “none”.
- Returns
- Return type
scale specification
Note
Input data expected: numetic codes or names of line types (i.e ‘dotdash’). The codes are: 0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash
Examples
>>> import pandas as pd >>> from lets_plot import * >>> x = range(6) >>> xend = [v + 2 for v in x] >>> y = x >>> l = range(1,7) >>> dat = pd.DataFrame({'x': x, 'y': y, 'xend':xend, 'l': l}) >>> ggplot(dat, aes('x', 'y', xend='xend', yend='y', linetype='l')) + ... geom_segment(size=2) + scale_linetype_identity()
-
lets_plot.scale_alpha_identity(name=None, breaks=None, labels=None, limits=None, na_value=None, guide='none')¶ Use this scale when your data has already been scaled. I.e. it already represents aesthetic values that ggplot2 can handle directly. This will not produce a legend unless you also supply the breaks and labels.
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
guide – Guide to use for this scale. Defaults to “none”.
- Returns
- Return type
scale specification
Note
Input data expected: numetic values in range [0..1]
Examples
>>> import pandas as pd >>> from lets_plot import * >>> x = [0,1,2] >>> y = x >>> a = [.3, .5, 0.8] >>> dat = pd.DataFrame({'x': x, 'y': y, 'a': a}) >>> ggplot(dat, aes('x', 'y', alpha='a')) + geom_point(size=15) + scale_alpha_identity()
-
lets_plot.scale_size_identity(name=None, breaks=None, labels=None, limits=None, na_value=None, guide='none')¶ Use this scale when your data has already been scaled. I.e. it already represents aesthetic values that ggplot2 can handle directly. This will not produce a legend unless you also supply the breaks and labels.
- Parameters
name (string) – The name of the scale - used as the axis label or the legend title
breaks (list of numerics) – A numeric vector of positions (of ticks)
labels (list of strings) – A vector of labels (on ticks)
limits (list) – Continuous scale: a numeric vector of length two providing limits of the scale. Discrete scale: a vector specifying the data range for the scale. and the default order of their display in guides.
guide – Guide to use for this scale. Defaults to “none”.
- Returns
- Return type
scale specification
Note
Input data expected: positive numetic values
Examples
>>> import pandas as pd >>> from lets_plot import * >>> x = [0,1,2] >>> y = x >>> s = [3, 9, 18] >>> dat = pd.DataFrame({'x': x, 'y': y, 's': s}) >>> ggplot(dat, aes('x', 'y', size='s')) + geom_point() + scale_size_identity()
-
lets_plot.theme(*, axis_title=None, axis_title_x=None, axis_title_y=None, axis_text=None, axis_text_x=None, axis_text_y=None, axis_ticks=None, axis_ticks_x=None, axis_ticks_y=None, axis_line=None, axis_line_x=None, axis_line_y=None, legend_position=None, legend_justification=None, legend_direction=None, axis_tooltip=None, axis_tooltip_x=None, axis_tooltip_y=None, **kwargs)¶ Use theme() to modify individual components of a theme, allowing you to control the appearance of all non-data components of the plot.
- Parameters
axis_title (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – label of axes
axis_title_x (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – x axis label
axis_title_y (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – y axis label
axis_text (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – tick labels along axes
axis_text_x (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – x axis tick labels
axis_text_y (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – y axis tick labels
axis_ticks (result of element_line() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – tick marks along axes
axis_ticks_x (result of element_line() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – x axis tick marks
axis_ticks_y (result of element_line() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – y axis tick marks
axis_line (result of element_line() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – lines along axes
axis_line_x (result of element_line() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – line along x axis
axis_line_y (result of element_line() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – line along y axis
legend_position ([‘none’ | ‘left’ | ‘right’ | ‘bottom’ | ‘top’] or two-element numeric vector.) – The position of legends. “none” - remove the plot legend.
legend_justification (“center” or two-element numeric vector.) – Anchor point for positioning legend.
legend_direction ([“horizontal” | “vertical”]) – Layout of items in legends.
axis_tooltip (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – axes tooltips
axis_tooltip_x (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – x axis tooltips
axis_tooltip_y (result of element_text() or [element_blank() | ‘blank’] to draw nothing and assign no space.) – y axis tooltips
- Returns
- Return type
theme specification
Examples
>>> import pandas as pd >>> from sklearn.datasets import make_blobs >>> X,y = make_blobs(n_samples=1000) >>> dat = {'x': X.T[0], 'y': X.T[1], 'variable': y} >>> dat = pd.DataFrame(dat) >>> colors = {0:'red', 1: 'blue', 2: 'green'} >>> dat['color'] = [colors[variable] for variable in dat['variable']] >>> ggplot(dat, aes(x='x', y='y')) + geom_point(aes(color='y')) + ... scale_color_gradient(guide=guide_colorbar(nbin=10,barheight= 8, barwidth=300)) + ... theme(legend_position='top')
-
lets_plot.element_blank()¶
-
lets_plot.layer_tooltips(lines=None)¶ Define tooltips.
- Parameters
‘lines’ (List of variables to show in the tooltip.) – Each element of the list can contain a variable name or the full specification of a tooltip line using the function ‘tooltip_line’:
tooltip_line(value = <variable_name>, label = <label_text>, format = <format>)
lines = None - default tooltips
lines = [] - no tooltips
- Returns
- Return type
layer tooltips specification
Examples
>>> import pandas as pd >>> from lets_plot import * >>> mpg_url = 'https://vincentarelbundock.github.io/Rdatasets/csv/ggplot2/mpg.csv' >>> mpg = pd.read_csv(mpg_url) >>> p = ggplot(mpg, aes(x='displ', y='hwy')) + geom_point(aes(color='cty', shape='drv'), ... tooltips=layer_tooltips(lines=[tooltip_line(value='color', label='city miles per gallon:')]))
-
lets_plot.tooltip_line(value=None, label=None, format=None)¶ Adjust the content of the tooltip’s line.
- Parameters
value – variable name
label – tooltip label
format – tooltip format
- Returns
- Return type
dictionary described the tooltip line specification
-
lets_plot.maptiles_zxy(url: str) → dict¶ - Parameters
url – Template for a standard raster ZXY tile provider with {z}, {x} and {y} wildcards, e.g. ‘http://my.tile.com/{z}/{x}/{y}.png’
- Returns
Tile provider settings
-
class
lets_plot.LetsPlot¶ Bases:
object-
classmethod
set(settings: Dict)¶
-
classmethod
setup_html(isolated_frame: bool = None, offline: bool = None, show_status: bool = False) → None¶ Configures Lets-Plot HTML output. Depending on the usage LetsPlot generates different HTML to show plots. In most cases LetsPlot will detect type of the environment automatically. Auto-detection can be overritten using this method parameters.
- Parameters
isolated_frame (bool, optional, default None - auto-detect) – If True, generate HTLM which can be used in iframe or in a standalone HTML document If False, pre-load Lets-Plot JS library. Notebook cell output will only consist of HTML for the plot rendering.
offline (bool, optional, default None - evaluated to ‘connected’ mode in production environment.) – If True, full Lets-Plot JS bundle will be added to the notebook. Use this option if you would like to work with notebook without the Internet connection. If False, load Lets-Plot JS library from CDN.
show_status (bool, optional, default False) – Whether to show status of loading of the Lets-Plot JS library. Only applicable when the Lets-Plot JS library is preloaded.
-
classmethod